angular.module('app',[])

.controller('appCtrl', ['$scope','$http', '$location', function($scope, $http, $location) {
	
	$scope.appName = "FoodTruck"
	$scope.galleryDataList
	$scope.slideDataList
	$scope.setDataList = function () {
		var responsePromise  = $http.get('./api/get/getGalleryItem.json')
		responsePromise .success(function(data) {
			$scope.galleryDataList = data.rows
			
		})
		
		var responsePromise  = $http.get('./api/get/slideData.json')
		responsePromise .success(function(data) {
			$scope.slideDataList = data.rows
			
		})

		$.mobile.changePage('#main-content')
	}
	
	
	$scope.$on('login success', function (event) {
		$scope.setDataList();
	})
	
}])

.controller('LoginCtrl', ['$scope','$http', function($scope, $http) {
	
	$scope.user = {
			email : 'test@test.com'
			,password : 'test1234'
	}
	
	$scope.loginSubmit = function () {

		var dataObject = {
		          email : $scope.user.email
		        , password  : $scope.user.password
		}

		var responsePromise  = $http.post("./api/post/login", dataObject)
		
		responsePromise .success(function(dataFromServer, status, headers, config) {
			
			//reset parameter
			$scope.user = {
					email : ''
					,password : ''
			}
			$scope.$emit('login success')
	        
	    })
		
		responsePromise .error(function(data, status, headers, config) {
			 alert(data)
	    })
	        
	}

}])





